﻿Imports System.Data.SqlClient
Public Class CNhanVien
#Region "Attribute"
    Dim _strMaNV As String
    Dim _strTenNV As String
    Dim _strNgaySinh As String
    Dim _iPhai As String
    Dim _strDiaChi As String
    Dim _strDienThoai As String
    Shared da As DataProvider
#End Region
#Region "Properties"
    Property MaNV As String
        Get
            Return _strMaNV
        End Get
        Set(ByVal value As String)
            _strMaNV = value
        End Set
    End Property
    Property TenNV As String
        Get
            Return _strTenNV
        End Get
        Set(ByVal value As String)
            _strTenNV = value
        End Set
    End Property
    Property NgaySinh As String
        Get
            Return _strNgaySinh
        End Get
        Set(ByVal value As String)
            _strNgaySinh = value
        End Set
    End Property
    Property Phai As String
        Get
            Return _iPhai
        End Get
        Set(ByVal value As String)
            _iPhai = value
        End Set
    End Property
    Property DiaChi As String
        Get
            Return _strDiaChi
        End Get
        Set(ByVal value As String)
            _strDiaChi = value
        End Set
    End Property
    Property DienThoai As String
        Get
            Return _strDienThoai
        End Get
        Set(ByVal value As String)
            _strDienThoai = value
        End Set
    End Property
#End Region
    Public Function LoadDSNV() As DataTable
        Dim dt As DataTable = Nothing
        da = New DataProvider()
        da.OpenConnect()
        Dim sql As String = "select * from NHANVIEN"
        dt = da.ShowData(sql)
        da.CloseConnect()
        Return dt
    End Function
    Public Function InsertNhanVien(ByVal nv As CNhanVien) As Integer
        Try
            da = New DataProvider()
            da.OpenConnect()
            Dim sql As String = "INSERT INTO NHANVIEN(TenNhanVien,NgaySinh,GioiTinh,DiaChi,DienThoai) VALUES(@TenNhanVien,@NgaySinh,@GioiTinh,@DiaChi,@DienThoai)"
            Dim cmd As New SqlCommand(sql, da.con)
            cmd.Parameters.AddWithValue("@TenNhanVien", nv.TenNV)
            cmd.Parameters.AddWithValue("@NgaySinh", nv.NgaySinh)
            cmd.Parameters.AddWithValue("@GioiTinh", nv.Phai)
            cmd.Parameters.AddWithValue("@DiaChi", nv.DiaChi)
            cmd.Parameters.AddWithValue("@DienThoai", nv.DienThoai)
            cmd.ExecuteNonQuery()
            Return 1
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Thông báo")
        Finally
            da.CloseConnect()
        End Try
        Return 0
    End Function
    Public Sub DeleteNhanVien(ByVal maNhanVien As String)
        da = New DataProvider
        da.OpenConnect()
        Dim sql As String = "DELETE FROM NHANVIEN WHERE MaNhanVien = @MaNhanVien"
        Dim cmd As New SqlCommand(sql, da.con)
        cmd.CommandText = sql
        cmd.Parameters.AddWithValue("@MaNhanVien", maNhanVien)
        cmd.ExecuteNonQuery()
    End Sub
    Public Sub UpdateNhanVien(ByVal nv As CNhanVien)
        Try
            da = New DataProvider()
            da.OpenConnect()
            Dim sql As String = "UPDATE NHANVIEN " + _
                                "SET TenNhanVien = @TenNhanVien, NgaySinh = @NgaySinh,GioiTinh = @GioiTinh,DiaChi = @DiaChi,DienThoai = @DienThoai " + _
                                "WHERE MaNhanVien = @MaNhanVien"
            Dim cmd As New SqlCommand(sql, da.con)
            cmd.Parameters.AddWithValue("@MaNhanVien", nv.MaNV)
            cmd.Parameters.AddWithValue("@TenNhanVien", nv.TenNV)
            cmd.Parameters.AddWithValue("@NgaySinh", nv.NgaySinh)
            cmd.Parameters.AddWithValue("@GioiTinh", nv.Phai)
            cmd.Parameters.AddWithValue("@DiaChi", nv.DiaChi)
            cmd.Parameters.AddWithValue("@DienThoai", nv.DienThoai)
            cmd.ExecuteNonQuery()
            MsgBox("Update Thành công", MsgBoxStyle.Information, "Thông báo")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Thông báo")
        Finally
            da.CloseConnect()
        End Try
    End Sub
    Public Function GetData(ByVal sql As String) As Object
        da = New DataProvider
        da.OpenConnect()
        Dim obj As New Object
        obj = da.GetData(sql)
        da.CloseConnect()
        Return obj
    End Function
End Class
